import numpy as np
import matplotlib.pyplot as plt

# 示例数据（根据你自己的数据进行替换）
methods = ['STDroid', 'MaMaDroid', 'Drebin', 'MsDroid', 'DetectBERT', 'MPDroid']
metrics = ['Acc', 'Pre', 'Rec', 'F1']

# 示例指标数据 (根据你的实验结果替换)
# STDroid = [0.9912, 0.9874, 0.9942, 0.9907]
# MaMaDroid = [0.9724, 0.9669, 0.9786, 0.9727]
# Drebin = [0.9777, 0.9779, 0.9777, 0.9777]
# DetectBERT = [0.9464, 0.9471, 0.9419, 0.9445]
# DexRay = [0.9483, 0.9412, 0.9529, 0.9470]

# muti
STDroid = [0.9912, 0.9874, 0.9942, 0.9907]
MaMaDroid = [0.9724, 0.9669, 0.9786, 0.9727]
Drebin = [0.9777, 0.9779, 0.9777, 0.9777]
MsDroid = [0.9483, 0.9412, 0.9529, 0.9470]
DetectBERT = [0.9464, 0.9471, 0.9419, 0.9445]
MPDroid = [0.9806, 0.9722, 0.9892, 0.9806]

color_map = {
    'STDroid':    '#ff0000',  # 橙
    'MaMaDroid':  '#808080',  # 蓝
    'Drebin':     '#bf00bf',  # 绿
    'MsDroid':    '#00bf00',  # 绿色
    'DetectBERT': '#00bfbf',  # 紫
    'MPDroid':    '#ffbf00',  # 金黄色
}


data = [STDroid, MaMaDroid, Drebin, MsDroid, DetectBERT, MPDroid]

# 雷达图绘制
angles = np.linspace(0, 2 * np.pi, len(metrics), endpoint=False).tolist()
angles += angles[:1]

fig, ax = plt.subplots(figsize=(8, 8), subplot_kw=dict(polar=True))


for method, values in zip(methods, data):
    values += values[:1]  # 循环闭合
    ax.plot(angles, values,
            color=color_map[method],     # ← 指定颜色
            linewidth=1.8,
            label=method,marker='o', markersize=3)
        # ax.fill(angles, values, alpha=0.1)

# ax.set_thetagrids(np.degrees(angles[:-1]), metrics, fontsize=12, weight='bold')
# ax.set_title('Binary Classification Performance Comparison', fontsize=15, y=1.1)
# ax.set_rlim(0.940, 0.995)  # 调整根据你的数据范围
# ax.grid(True)
# ax.legend(loc='upper right', bbox_to_anchor=(1.1, 1.05))

# plt.show()

# 角度标签
ax.set_thetagrids(np.degrees(angles[:-1]), metrics,
                  fontsize=15, weight='bold')

# 标题
ax.set_title('Binary Classification Performance Comparison',
             fontsize=15, y=1.1)

# 1) 先固定径向范围
ax.set_rlim(0.83, 1)

# 2) 再设置刻度：每 0.01 一圈
# ticks = np.arange(0.93, 1.00, 0.015)
ticks = np.arange(0.85, 1, 0.05)
ax.set_yticks(ticks)
ax.set_yticklabels([f"{t:.3f}" for t in ticks], fontsize=15)
 
# 网格、图例
ax.grid(True, linestyle='--', linewidth=0.8, alpha=0.7)
legend = ax.legend(
    loc='upper right',
    bbox_to_anchor=(1.10, 1.05),   # 视情况微调
    frameon=True,                  # 打开框
    facecolor='none',           # 框内底色
    edgecolor='#808080',           # 框线颜色
    framealpha=1,                  # 不透明
    fontsize=15,
)

plt.savefig('bi-2-zq.png', dpi=300)
